﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Supermarket;

namespace XLSupermarket.Admin
{
    public partial class AdminForm : Form
    {
        public AdminForm()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("您确认退出吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result == DialogResult.OK) System.Environment.Exit(0);

        }

        private void AdminForm_Load(object sender, EventArgs e)
        {
            try { 
            this.panel3.Show();
            this.panel4.Hide();

            string userName = LoginForm.UserName_Value;//账号
            string sql = "select Src from EP_Number where UserName='" + userName + "'";
            DataTable sdr = DBHelper.FillData(sql);
            string path = sdr.Rows[0]["Src"].ToString();
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
            Image img = Image.FromStream(fs);
            pictureBox2.Image = img;
            //获取从主页面获取的员工姓名
            string sql1 = "select EP_Name from EP_Number en,EP_information ei where en.EP_ID = ei.EP_ID and en.UserName = '" + userName + "'";
            DataTable sdr1 = DBHelper.FillData(sql1);
            string name = sdr1.Rows[0][0].ToString();
            this.label2.Text = name;
            //只有店长可以返回主界面
            string sql3 = "select Staff_Name from EP_Number en,EP_information ei where en.EP_ID = ei.EP_ID and en.UserName = '" + userName + "'";
            DataTable sdr3 = DBHelper.FillData(sql3);
            if (sdr3.Rows[0][0].ToString() == "店长") this.button9.Show();
            else this.button9.Hide();
            //获取从主页面获取的员工姓名
            sql1 = "select EP_Name from EP_Number en,EP_information ei where en.EP_ID = ei.EP_ID and en.UserName = '" + userName + "'";
            sdr1 = DBHelper.FillData(sql1);
            name = sdr1.Rows[0][0].ToString();
            this.label3.Text = name;
            }
            catch (Exception ex)
            {
                MessageBox.Show("出现错误：" + ex.Message);
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            MainInterface.SuperAdmin.SuperAdminForm sc = new MainInterface.SuperAdmin.SuperAdminForm();
            sc.Show();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            Admin.Ad_zscg.Ad_zscg cos = new Admin.Ad_zscg.Ad_zscg();
            cos.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Account.Information.seletInformationForm AISF = new Account.Information.seletInformationForm();
            AISF.ShowDialog();
        }
        private void button4_Click_1(object sender, EventArgs e)
        {

            //返回系统主界面
            MainInterface.MainForm MF = new MainInterface.MainForm();
            this.Hide();
            MF.Show();
        }
        private void button5_Click(object sender, EventArgs e)
        {
            //注销回到登录界面
            LoginForm loginForm = new LoginForm();
            DialogResult result = MessageBox.Show("你确定要返回嘛?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                this.Hide();
                loginForm.Show();
            }
        }
        private void AdminForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult result = MessageBox.Show("您确认退出吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result == DialogResult.OK) System.Environment.Exit(0);
            else e.Cancel = true;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.panel4.Show();
            this.panel3.Hide();
        }
        private void button6_Click(object sender, EventArgs e)
        {
            this.panel3.Show();
            this.panel4.Hide();
        }
        private void button9_Click(object sender, EventArgs e)
        {
            MainInterface.MainForm MIMF = new MainInterface.MainForm();
            this.Hide();
            MIMF.Show();
        }

        private void button9_Click_1(object sender, EventArgs e)
        {
            MainInterface.MainForm MF = new MainInterface.MainForm();
            this.Hide();
            MF.Show();
        }
    }
}
